<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class BaseModel extends Model
{
    /**
     * 此方法是解决where查询时候多个where语句需要不断的链式写where
     * 调用示例：Student::multiwhere([‘female’=>1, ’teacher_id’ => 4, ‘class_id’ => 3])->get();
     */
    public static function scopeMultiwhere($query, $arr)
    {
        if (!is_array($arr)) {
            return $query;
        }

        foreach ($arr as $key => $value) {
            $query = $query->where($key, $value);
        }
        return $query;
    }


    /**
     *  批量插入的方法
    */
    public static function batchInsertData($table,$data_arr){
        if(!$data_arr){
            return ;
        }
      return  DB::table($table)->insert($data_arr);
    }
}
